<?php

/**
 * @copyright	Copyright (c) 2013 diem. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */
// no direct access
defined('_JEXEC') or die;
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('*');
$query->from('#__lop');
$query->order('ma_hocki DESC');
$db->setQuery($query,0,$params->get('count', 12));
$rows = $db->loadObjectList(); ?>
<p><a href="modules/mod_diem/diem.xml"><img src="modules/mod_diem/images/rss.png" width="20%" />RSS</a></p>
<?php
foreach ($rows AS $key => $item) {
  if($item->diem_gk !="") {  ?>
<p><a href="<?php echo JRoute::_('index.php?option=com_sinhvien&view=lop&id=' . (int) $item->id); ?>" alt='<?php echo $item->diem_gk; ?>'>Điểm giữa kì môn <?php echo $item->ten_hp; ?> kì <?php echo $item->ma_hocki; ?> </a></p>
    <?php
  }
   if($item->diem_ck !="") {  ?>
<p><a href="<?php echo JRoute::_('index.php?option=com_sinhvien&view=lop&id=' . (int) $item->id); ?>" alt='<?php echo $item->diem_ck; ?>'>Điểm cuối kì môn <?php echo $item->ten_hp; ?> kì <?php echo $item->ma_hocki; ?> </a></p>
    <?php
  }
}
?>
<?php
$dom=new DomDocument("1.0","utf-8");
    $rss = $dom->createElement('rss');
	$rss->setAttribute("version","2.0");
    $dom->appendChild($rss);
        $channel=$dom->createElement("channel");
		$dom->appendChild($channel);
		
		$title=$dom->createElement("title");
		$dom->appendChild($title);
        $title_text=$dom->createTextNode("Điểm thi môn học");
        $title->appendChild($title_text);
		$channel->appendChild($title);
		
		foreach ($rows AS $key => $items) {
		
		if($items->diem_gk !="") { 
		
		$item=$dom->createElement("item");
		$dom->appendChild($item);
		
		$title=$dom->createElement("title");
		$dom->appendChild($title);
        $title_text=$dom->createTextNode("Điểm giữa kì môn ".$items->ten_hp." kì ".$items->ma_hocki);
        $title->appendChild($title_text);
		$item->appendChild($title);
		
		$link=$dom->createElement("link");
		$dom->appendChild($link);
		$link_text=$dom->createTextNode("http:".$_SERVER['HTTP_HOST'].JRoute::_('index.php?option=com_sinhvien&view=lop&id=' . (int) $items->id));
        $link->appendChild($link_text);
		$item->appendChild($link);
		
		$channel->appendChild($item);
			}
			
			if($items->diem_ck !="") { 
		
		$item=$dom->createElement("item");
		$dom->appendChild($item);
		
		$title=$dom->createElement("title");
		$dom->appendChild($title);
        $title_text=$dom->createTextNode("Điểm cuối kì môn ".$items->ten_hp." kì ".$items->ma_hocki);
        $title->appendChild($title_text);
		$item->appendChild($title);
		
		$link=$dom->createElement("link");
		$dom->appendChild($link);
		$link_text=$dom->createTextNode("http:".$_SERVER['HTTP_HOST'].JRoute::_('index.php?option=com_sinhvien&view=lop&id=' . (int) $items->id));
        $link->appendChild($link_text);
		$item->appendChild($link);
		
		$channel->appendChild($item);
			}
		}
		
        $rss->appendChild($channel);
		
    $dom->formatOutput=true;
    $dom->saveXML();
    $dom->save("modules/mod_diem/diem.xml"); 
	?>


